import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseFilters,
  Put,
} from '@nestjs/common';
import {
  ApiResponse,
  ApiTags,
  ApiQuery,
  ApiBearerAuth,
  ApiBody,
  ApiParamOptions,
  ApiOperation,
} from '@nestjs/swagger';
import { PhotoService } from './photo.service';
import { CreatePhotoDto } from './dto/create-photo.dto';
import { Photo, PhotoStatus } from './classes/photo';
import { UpdatePhotoDto } from './dto/update-photo.dto';
import CustomException from '../common/exception';

@ApiBearerAuth()
@ApiTags('Photo')
@Controller('photo')
@UseFilters(new CustomException.NotFoundExceptionFilter())
export class PhotoController {
  constructor(private readonly photoService: PhotoService) {}
  @Get('list')
  // 告诉 swagger 文档 给出参数输入框
  // @ApiQuery({ name: 'name', required: true })
  // @ApiQuery({ name: 'isPublished', enum: PhotoStatus })
  @ApiOperation({ summary: '获取全部照片信息' })
  @ApiResponse({
    status: 200,
    description: '返回当前所有照片列表',
    type: Photo,
  })
  async findAll() {
    return await this.photoService.findAll();
  }

  @Get(':id')
  @ApiOperation({ summary: '获取某个照片信息，找不到就会报错' })
  async findOne(@Param('id') id: string) {
    return await this.photoService.findOne(id);
  }

  @Post('create')
  @ApiOperation({ summary: '添加照片' })
  async create(@Body() createPhotoDto: CreatePhotoDto) {
    return await this.photoService.create(createPhotoDto);
  }

  @Put()
  @ApiOperation({ summary: '更新照片信息' })
  async update(@Body() updatePhotoDto: UpdatePhotoDto) {
    return await this.photoService.update(updatePhotoDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除照片信息' })
  async delete(@Param('id') id: number) {
    return this.photoService.delete(id);
  }
}
